/*
 * Copyright (C) 2014 Lucid Wolf
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.lucidhex.hex;

import com.lucidhex.LucidBoard;
import com.lucidhex.LucidXMLObject;
import com.lucidhex.io.LucidWorldParser;
import com.lucidhex.viewer.LucidIcon;
import java.awt.Color;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

/**
 *  
 * @author Lucid Wolf
 */
public class LucidHexType implements LucidXMLObject{
    public static LucidHexType NULL_HEX = createNULLHEX();
    // not exported
    private boolean writeOut = true;
    // Attributes
    private Color backGroundColor = Color.BLACK;
    private Color foreGroundColor = Color.BLACK;
    private String typeName = "";
    // children
    private LucidIcon foreGroundSVG = null;
    private HashMap<String, LucidHexResource> resources = new HashMap<>();
    private HashMap<String, String> attributes = new HashMap<>();

    public LucidHexType(){}
    public LucidHexType(String typeName){
        this.typeName = typeName;
        writeOut = false;
    }
    public LucidHex makeNewHex(LucidBoard lb){
        LucidHex out = new LucidHex(lb, this);
        return out;
    }
    @Override
    public String getTag() {
        return "LucidHexType";
    }

    @Override
    public void addField(String key, String value){
        if(key.equalsIgnoreCase("TypeName")){
            typeName = value;
        }else if(key.equalsIgnoreCase("BackGround")){
            backGroundColor = new Color(Integer.parseInt(value));
        }else if(key.equalsIgnoreCase("ForeGround")){
            foreGroundColor = new Color(Integer.parseInt(value));
        }
    }

    @Override
    public void getChildren(Collection<Object> children) {
        children.add(foreGroundSVG);
        children.add(resources.values());
    }

    @Override
    public void getFields(Map<String, String> attrib) {
        attrib.put("TypeName", typeName);
        attrib.put("BackGround", ""+backGroundColor.getRGB());
        attrib.put("ForeGround", ""+foreGroundColor.getRGB());
    }
    @Override
    public void addChild(Object aChild) {
        if(aChild instanceof LucidIcon){
            foreGroundSVG = (LucidIcon)aChild;
        }
    } 
    // this matters because if its internal style it 
    @Override
    public boolean writeToXml() {
        return writeOut;
    }

    public void setBackgroundColor(Color aColor) {
        backGroundColor = aColor;
    }
    public void setForegroundColor(Color aColor) {
        foreGroundColor = aColor;
    }
    public void setTypeName(String aName) {
        typeName = aName;
    }

    public void addAttribute(String name, String defValue) {
        
    }

    private static LucidHexType createNULLHEX() {
        LucidHexType out = new LucidHexType();
        out.setBackgroundColor(Color.BLACK);
        out.setForegroundColor(Color.WHITE);
        out.setTypeName("BOOPING_NULL");
        return out;
    }

    public String getTypeName() {
        return typeName;
    }

    public Color getBackgroundColor() {
        return backGroundColor;
    }
    public Color getForegroundColor() {
        return foreGroundColor;
    }

    @Override
    public void parseLink(LucidWorldParser parser) {
        
    }

    public LucidIcon getForegroundIcon() {
        return foreGroundSVG;
    }

}
